package com.cuitrip.business.order.ui;

import android.content.Context;
import android.view.View;
import android.widget.CheckedTextView;

import com.cuitrip.business.order.OrderCreateActivity;
import com.cuitrip.business.order.model.PersonSelectModel;
import com.cuitrip.service.R;
import com.lab.adapter.BaseHolderView;
import com.lab.adapter.IAdapterData;

import butterknife.Bind;
import butterknife.ButterKnife;


/**
 * 圆形图片
 *
 * @author ak
 */
public class PersonNumberHolderView extends BaseHolderView {

    @Bind(R.id.person_item)
    CheckedTextView personNumberCheckedTextView;

    private OrderCreateActivity.OnSelectCallback onSelectCallback;

    public PersonNumberHolderView(Context context) {
        super(context, R.layout.person_item);
    }

    @Override
    public void initView(View rootView) {
        ButterKnife.bind(this);
    }

    @Override
    public void bindData(IAdapterData data, final int position) {
        if (data instanceof PersonSelectModel) {
            PersonSelectModel personSelectModel = (PersonSelectModel) data;
            personNumberCheckedTextView.setText(String.valueOf(personSelectModel.getPersonNum()));
            personNumberCheckedTextView.setVisibility(personSelectModel.isEnabled() ? View.VISIBLE : View.INVISIBLE);
            personNumberCheckedTextView.setChecked(personSelectModel.isSelected());
            personNumberCheckedTextView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    if (onSelectCallback != null) {
                        onSelectCallback.onSelect(position);
                    }
                }
            });
        }
    }

    public void setOnSelectCallback(OrderCreateActivity.OnSelectCallback onSelectCallback) {
        this.onSelectCallback = onSelectCallback;
    }
}
